package com.ychs.lawyer.controller;

import com.github.pagehelper.PageHelper;
import com.ychs.lawyer.bean.R;
import com.ychs.lawyer.bean.Seal;
import com.ychs.lawyer.service.SealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: clh
 * @Date: 2024/08/05/10:44
 * @Description:
 */
@Api(tags = "用章管理接口")
@RestController
@RequestMapping("/seal")
@Slf4j
public class SealController {
    @Autowired
    private SealService sealService;

    @ApiOperation("根据条件获取所有用章记录")
    @GetMapping("/getSealsByCondition")
    public R<?> getSealsByCondition(Seal seal){
        PageHelper.startPage(seal.getPage(),seal.getPageSize());
        List<Seal> seals = sealService.getSealsByCondition(seal);
        return R.success(seals);
    }

    @ApiOperation("修改用章记录")
    @PostMapping("/editSeal")
    public R<?> editSeal(@RequestBody Seal seal){
          log.info("seal{}",seal);
          int res  = sealService.editSeal(seal);
         return res > 0?R.success():R.fail();
    }

    @ApiOperation("添加用章记录")
    @PostMapping("/addSeal")
    public R<?> addSeal(@RequestBody Seal seal){
          int res  = sealService.addSeal(seal);
         return res > 0?R.success():R.fail();
    }
}
